home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jaz_clib.arc / JAZPRINT.DMO < prev    next >
Text File  |  1989-04-09  |  8KB  |  277 lines

  1. /*
  2. ┌────────────────────────────────────────────────────────────────────────────┐
  3. │ Title   : jazprint.dmo                             │
  4. │ Purpose : Allow multiple printing of programs, with wildcards and various  │
  5. │                                         │
  6. │        formatting options.                          │
  7. │  -d specifies double strike printing                         │
  8. │  -e specifies emphasized printing                         │
  9. │  -t specifies title of document + time and date                 │
  10. │  -w specifies wide (compressed) listing                     │
  11. │  -n specifies to number the lines                         │
  12. │  -u specifies user chars to send (in hex). i.e jazprint *.* -u 1b471b45    │
  13. │  -mn specifies multiple copies where n is the number of copies         │
  14. │                                         │
  15. │Written using Lattice C v 2.15e, translated to Microsoft C v3.0  on 1/15/86 │
  16. │Version changed to use stdout for printing on 7/10/86                 │
  17. │                                         │
  18. │    Written by Jack Zucker - 75766,1336    301-794-5950             │
  19. └────────────────────────────────────────────────────────────────────────────┘
  20. */
  21. #include <stdio.h>           /* standard header file      */
  22. #include <time.h>           /* Ms C time struct      */
  23. #include <stdlib.h>           /* standard functions      */
  24. #include <ctype.h>           /* isdigit, islower, etc   */
  25. #include <jaz.h>           /* standard jaz functions  */
  26. #include <jzdirect.h>           /* jz directory stuff      */
  27.  
  28. #define VERSION "3.0"
  29. #define FORMFEED 0x0c          /* form feed          */
  30. #define PGLEN 60          /* length of a page      */
  31. #define COMPRS 0x0f          /* epson compressed code      */
  32. #define BUFSIZE 255          /* Number of chars to read  */
  33. #define ESC 0x1b          /* hex esc code          */
  34. #define DBL 71              /* epson double strike code */
  35. #define EMPH 69           /* epson emphasized code      */
  36.  
  37. int colno,lineslft,width = 81;
  38.  
  39. struct tm *wtime;
  40. char *glbtime;
  41.  
  42.                     /* switches */
  43. int NUMBER = 0,WIDE = 0,TITLE = 0;
  44. int DOUBLE = 0,EMPHASIZ = 0,MULTIPLE = 1;
  45. char USERSTR[64];            /* string for user printing */
  46.  
  47. char mask[13];                /* global variables */
  48. char wpath[64],wtemp[64];
  49. int gpage;
  50.  
  51. main (argc,argv)
  52. int argc;
  53. char **argv;
  54.  
  55. {
  56.  
  57.   TDIR wdir;
  58.   char *HEX= "0123456789ABCDEF";
  59.   char buf[BUFSIZE + 1],*s,*ch;
  60.   char *p,*malloc();
  61.   long wtics;
  62.   int c,n,w;
  63.   FILE *fd;
  64.   int werr;
  65.   int werror = 0;        /* command error flag */
  66.   char wstr[64];
  67.  
  68.   fprintf(stderr,"\n\n%s%s%s\n","JAZPRINT v",VERSION,
  69.       " by JazSoft (Jack A. Zucker) 301-794-5950 | CIS:75766,1336");
  70.  
  71.   if (argc > 1) {
  72.  
  73.     strcpy(mask,*++argv);          /* get full path name */
  74.  
  75.     jzprsfil(mask,wpath,wstr);          /* parse out path and file name */
  76.  
  77.     time(&wtics);
  78.     wtime = localtime(&wtics);
  79.     glbtime = asctime(wtime);
  80.     w = strlen(glbtime);
  81.     glbtime[--w] = '\0';
  82.     while (--argc > 0 && (*++argv)[0] == '-')    /* parse through options */
  83.       for (s = argv[0]+1; *s ; s ++)
  84.     switch(toupper(*s)) {
  85.       case 'W' :        /* wide printing */
  86.         WIDE = 1;
  87.         break;
  88.       case 'N' :        /* number lines  */
  89.         NUMBER = 1;
  90.         break;
  91.       case 'T' :
  92.         TITLE = 1;       /* title and heading */
  93.         break;
  94.       case 'D' :
  95.         DOUBLE = 1;   /* double strike     */
  96.         break;
  97.       case 'E' :
  98.         EMPHASIZ = 1; /* emphasized        */
  99.         break;
  100.       case 'M' :
  101.         MULTIPLE = 0;      /* assume no copies */
  102.         s ++;
  103.         while (isdigit(*s))
  104.           MULTIPLE = MULTIPLE * 10 + (*s++ - 48);
  105.         s --;
  106.         break;
  107.       case 'U' :
  108.         p = *(argv+1);          /* get pointer to hex string */
  109.  
  110.         if (strlen(p) & 1) {      /* odd length of hex string */
  111.           fprintf(stderr,"\nHex digits must be two chars long each !");
  112.           werror = 1;          /* set error flag */
  113.           break;
  114.         }
  115.         *USERSTR = 0;          /* start out with null string */
  116.         w = 0;
  117.         while (*p)      {          /* convert hex to binary to char */
  118.           c = index(HEX,toupper(*p)) << 4 ; /* get first hex digit */
  119.           p++;
  120.           c += index(HEX,toupper(*p));
  121.           p++;
  122.           USERSTR[w++] = c;         /* store char in string */
  123.         }
  124.         USERSTR[w] = 0;            /* terminate string */
  125.         break;
  126.       default:      /* invalid option */
  127.         fprintf(stderr,"\nIllegal option %c",*s);
  128.         werror = 1;
  129.         break;
  130.     }
  131.   }
  132.   else
  133.     werror = 1;
  134.                           /* help or bad options */
  135.   if (werror || (mask[0] == '?' && strlen(mask) == 1)) {
  136.     fprintf(stderr,"\nusage: JAZPRINT [filespec] (including wildcards)\
  137. [-detwnum]\n");
  138.     fprintf(stderr,"\n\t-d specifies double strike printing");
  139.     fprintf(stderr,"\n\t-e specifies emphasized printing");
  140.     fprintf(stderr,"\n\t-t specifies title of document + time and date");
  141.     fprintf(stderr,"\n\t-w specifies wide (compressed) listing");
  142.     fprintf(stderr,"\n\t-n specifies to number the lines");
  143.     fprintf(stderr,"\n\t-u specifies user chars to send (in hex). i.e \
  144. jazprint *.* -u 1B471B45");
  145.     fprintf(stderr,"\n\t-mn specifies multiple copies where n is the number \
  146. of copies\n");
  147.     exit(1);
  148.   }
  149.  
  150.   while (MULTIPLE -- ) {         /* allow for mult copies */
  151.     werr = jzfndfst(mask,32,&wdir);  /* get first matching file */
  152.     if (!werr)
  153.       do {                  /* until no more files     */
  154.     strcpy(wtemp,wpath);
  155.     strcat(wtemp,wdir.name);
  156.     if (!( fd = fopen(wtemp,"r"))) {   /* open for read only    */
  157.       /* bad file or it ain't there */
  158.       fprintf(stderr,"\nCan't find %s",wdir.name);
  159.       exit(1);
  160.      }
  161.  
  162.     fprintf(stderr,"\nPrinting: %s . . .",wdir.name);
  163.     getflags();             /* look at switch settings */
  164.     gpage = 0;             /* set page for this file */
  165.     formfeed (wdir.name);         /* page feed        */
  166.  
  167.                        /* while not eof do begin */
  168.     while ( (ch = fgets(buf,BUFSIZE,fd)) ) {
  169.       if (linepr(buf,wdir.name)) continue;      /* main print routine      */
  170.       if (! lineslft) formfeed (wdir.name); /* formfeed if appropriate */
  171.     }
  172.  
  173.     printf("\n");                       /* flush print buffer      */
  174.     fclose(fd);                /* close input file        */
  175.     werr = jzfndnxt(&wdir);         /* get next matching file  */
  176.       } while (! werr);
  177.     else {
  178.       fprintf(stderr,"No match for %s",mask);
  179.       exit(1);
  180.     }
  181.   }
  182. }
  183.  
  184.  
  185. linepr (string,fname)
  186. char *string;
  187. char *fname;
  188. {
  189.   char c;
  190.   int ffflag = 0;
  191.   static int wline = 0;
  192.  
  193.   while ( c = *string ++) {
  194.     if ( ( ! colno ) && NUMBER ) {
  195.       printf("%d",++wline);
  196.       colno += 6;
  197.     }
  198.     switch (c) {
  199.  
  200.       case FORMFEED :
  201.     ffflag = 1;
  202.     break;
  203.  
  204.       case '\n' :
  205.     printf("\n");
  206.     colno = 0;
  207.     if (! (lineslft --)) formfeed (fname);
  208.     break;
  209.  
  210.       case '\t' :
  211.     do {
  212.       printf(" ");
  213.       colno ++;
  214.       if (! ( ( (NUMBER) ? width - 8 : width) - colno ) ) {
  215.         printf("\n");
  216.         if (! (lineslft --)) formfeed (fname);
  217.         colno = 0;
  218.       }
  219.     } while ( colno % 8 );
  220.     break;
  221.  
  222.       default:
  223.     printf("%c",c);
  224.     colno ++;
  225.     if (! ( ( (NUMBER) ? width - 8 : width) - colno ) ) {
  226.       printf("\n");
  227.       if (! (lineslft --)) formfeed (fname);
  228.       colno = 0;
  229.     }
  230.     } /* switch */
  231.   }
  232.   if (ffflag) formfeed (fname);
  233.   return ffflag;
  234. }
  235.  
  236.  
  237. formfeed (fname)
  238. char *fname;
  239. {
  240.   printf("%c",FORMFEED);                /* go to top of next page */
  241.   if (TITLE) heading(fname);
  242.   lineslft = PGLEN - 4;
  243.   colno = 0;
  244. }
  245.  
  246. #define EMPHON    "\n\x1bE\x1bG"
  247. #define EMPHOFF "\n\n\n\r\x1bF\x1bH"
  248. heading(fname)
  249. char *fname;
  250. {
  251.  
  252.   gpage ++;
  253.  
  254.   printf("%sListing of %s on %s     PAGE: %5d%s",EMPHON,fname,glbtime,
  255.      gpage,EMPHOFF);
  256.  
  257.   getflags();
  258.  
  259. }
  260.  
  261.  
  262. getflags()
  263. {
  264.  
  265.   if (WIDE) {
  266.     printf("%c",COMPRS);
  267.     width = 133;
  268.   }
  269.  
  270.   if (DOUBLE) printf("%c%c",ESC,DBL);
  271.  
  272.   if (EMPHASIZ) printf("%c%c",ESC,EMPH);
  273.  
  274.   printf(*USERSTR ? "%s" : "" ,USERSTR);
  275. }
  276.  
  277.